

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>federatedml.param.intersect_param &mdash; FATE 1.0 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="../../../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../../../_static/jquery.js"></script>
        <script type="text/javascript" src="../../../_static/underscore.js"></script>
        <script type="text/javascript" src="../../../_static/doctools.js"></script>
        <script type="text/javascript" src="../../../_static/language_data.js"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> FATE
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <!-- Local TOC -->
              <div class="local-toc"></div>
            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">FATE</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html">Docs</a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>federatedml.param.intersect_param</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for federatedml.param.intersect_param</h1><div class="highlight"><pre>
<span></span><span class="ch">#!/usr/bin/env python</span>
<span class="c1"># -*- coding: utf-8 -*-</span>

<span class="c1">#</span>
<span class="c1">#  Copyright 2019 The FATE Authors. All Rights Reserved.</span>
<span class="c1">#</span>
<span class="c1">#  Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1">#  you may not use this file except in compliance with the License.</span>
<span class="c1">#  You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1">#      http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1">#  Unless required by applicable law or agreed to in writing, software</span>
<span class="c1">#  distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1">#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1">#  See the License for the specific language governing permissions and</span>
<span class="c1">#  limitations under the License.</span>
<span class="c1">#</span>
<span class="kn">import</span> <span class="nn">copy</span>

<span class="kn">from</span> <span class="nn">arch.api.utils.log_utils</span> <span class="k">import</span> <span class="n">getLogger</span>
<span class="kn">from</span> <span class="nn">federatedml.param.base_param</span> <span class="k">import</span> <span class="n">BaseParam</span>
<span class="kn">from</span> <span class="nn">federatedml.util</span> <span class="k">import</span> <span class="n">consts</span>

<span class="n">LOGGER</span> <span class="o">=</span> <span class="n">getLogger</span><span class="p">()</span>


<div class="viewcode-block" id="EncodeParam"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.intersect_param.EncodeParam">[docs]</a><span class="k">class</span> <span class="nc">EncodeParam</span><span class="p">(</span><span class="n">BaseParam</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define the encode method</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    salt: the src data string will be str = str + salt, default by empty string</span>

<span class="sd">    encode_method: str, the encode method of src data string, it support md5, sha1, sha224, sha256, sha384, sha512, default by None</span>

<span class="sd">    base64: bool, if True, the result of encode will be changed to base64, default by False</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">salt</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">encode_method</span><span class="o">=</span><span class="s1">&#39;none&#39;</span><span class="p">,</span> <span class="n">base64</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">salt</span> <span class="o">=</span> <span class="n">salt</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encode_method</span> <span class="o">=</span> <span class="n">encode_method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">base64</span> <span class="o">=</span> <span class="n">base64</span>

<div class="viewcode-block" id="EncodeParam.check"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.intersect_param.EncodeParam.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">salt</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s2">&quot;str&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;encode param&#39;s salt </span><span class="si">{}</span><span class="s2"> not supported, should be str type&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">salt</span><span class="p">))</span>

        <span class="n">descr</span> <span class="o">=</span> <span class="s2">&quot;encode param&#39;s &quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">encode_method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">encode_method</span><span class="p">,</span>
                                                            <span class="p">[</span><span class="s2">&quot;none&quot;</span><span class="p">,</span> <span class="s2">&quot;md5&quot;</span><span class="p">,</span> <span class="s2">&quot;sha1&quot;</span><span class="p">,</span> <span class="s2">&quot;sha224&quot;</span><span class="p">,</span> <span class="s2">&quot;sha256&quot;</span><span class="p">,</span> <span class="s2">&quot;sha384&quot;</span><span class="p">,</span>
                                                             <span class="s2">&quot;sha512&quot;</span><span class="p">],</span>
                                                            <span class="n">descr</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">base64</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s2">&quot;bool&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;encode param&#39;s base64 </span><span class="si">{}</span><span class="s2"> not supported, should be bool type&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">encode_param</span><span class="o">.</span><span class="n">base64</span><span class="p">))</span>

        <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Finish encode parameter check!&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="kc">True</span></div></div>


<div class="viewcode-block" id="IntersectParam"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.intersect_param.IntersectParam">[docs]</a><span class="k">class</span> <span class="nc">IntersectParam</span><span class="p">(</span><span class="n">BaseParam</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define the intersect method</span>

<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    intersect_method: str, it supports &#39;rsa&#39; and &#39;raw&#39;, default by &#39;raw&#39;</span>

<span class="sd">    random_bit: positive int, it will define the encrypt length of rsa algorithm. It effective only for intersect_method is rsa</span>

<span class="sd">    is_send_intersect_ids: bool. In rsa, &#39;is_send_intersect_ids&#39; is True means guest will send intersect results to host, and False will not.</span>
<span class="sd">                            while in raw, &#39;is_send_intersect_ids&#39; is True means the role of &quot;join_role&quot; will send intersect results and the other will get them.</span>
<span class="sd">                            Default by True.</span>

<span class="sd">    is_get_intersect_ids: bool, In rsa, it will get the results from other. It effective only for rsa and only be True will other&#39;s &#39;is_send_intersect_ids&#39; is True.Default by True</span>

<span class="sd">    join_role: str, it supports &quot;guest&quot; and &quot;host&quot; only and effective only for raw. If it is &quot;guest&quot;, the host will send its ids to guest and find the intersection of</span>
<span class="sd">                ids in guest; if it is &quot;host&quot;, the guest will send its ids. Default by &quot;guest&quot;.</span>

<span class="sd">    with_encode: bool, if True, it will use encode method for intersect ids. It effective only for &quot;raw&quot;.</span>

<span class="sd">    encode_params: EncodeParam, it effective only for with_encode is True</span>

<span class="sd">    only_output_key: bool, if true, the results of intersection will include key and value which from input data; if false, it will just include key from input</span>
<span class="sd">                    data and the value will be empty or some useless character like &quot;intersect_id&quot;</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">intersect_method</span><span class="o">=</span><span class="n">consts</span><span class="o">.</span><span class="n">RAW</span><span class="p">,</span> <span class="n">random_bit</span><span class="o">=</span><span class="mi">128</span><span class="p">,</span> <span class="n">is_send_intersect_ids</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                 <span class="n">is_get_intersect_ids</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">join_role</span><span class="o">=</span><span class="s2">&quot;guest&quot;</span><span class="p">,</span> <span class="n">with_encode</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">encode_params</span><span class="o">=</span><span class="n">EncodeParam</span><span class="p">(),</span>
                 <span class="n">only_output_key</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">intersect_method</span> <span class="o">=</span> <span class="n">intersect_method</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">random_bit</span> <span class="o">=</span> <span class="n">random_bit</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_send_intersect_ids</span> <span class="o">=</span> <span class="n">is_send_intersect_ids</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">is_get_intersect_ids</span> <span class="o">=</span> <span class="n">is_get_intersect_ids</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">join_role</span> <span class="o">=</span> <span class="n">join_role</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">with_encode</span> <span class="o">=</span> <span class="n">with_encode</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">encode_params</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">encode_params</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">only_output_key</span> <span class="o">=</span> <span class="n">only_output_key</span>

<div class="viewcode-block" id="IntersectParam.check"><a class="viewcode-back" href="../../../federatedml.param.html#federatedml.param.intersect_param.IntersectParam.check">[docs]</a>    <span class="k">def</span> <span class="nf">check</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">descr</span> <span class="o">=</span> <span class="s2">&quot;intersect param&#39;s&quot;</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">intersect_method</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">intersect_method</span><span class="p">,</span>
                                                                  <span class="p">[</span><span class="n">consts</span><span class="o">.</span><span class="n">RSA</span><span class="p">,</span> <span class="n">consts</span><span class="o">.</span><span class="n">RAW</span><span class="p">],</span>
                                                                  <span class="n">descr</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">random_bit</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">[</span><span class="s2">&quot;int&quot;</span><span class="p">]:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;intersect param&#39;s random_bit </span><span class="si">{}</span><span class="s2"> not supported, should be positive integer&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">random_bit</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">is_send_intersect_ids</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s2">&quot;bool&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;intersect param&#39;s is_send_intersect_ids </span><span class="si">{}</span><span class="s2"> not supported, should be bool type&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">is_send_intersect_ids</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">is_get_intersect_ids</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s2">&quot;bool&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;intersect param&#39;s is_get_intersect_ids </span><span class="si">{}</span><span class="s2"> not supported, should be bool type&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">is_get_intersect_ids</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">join_role</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">check_and_change_lower</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">join_role</span><span class="p">,</span>
                                                           <span class="p">[</span><span class="n">consts</span><span class="o">.</span><span class="n">GUEST</span><span class="p">,</span> <span class="n">consts</span><span class="o">.</span><span class="n">HOST</span><span class="p">],</span>
                                                           <span class="n">descr</span><span class="p">)</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">with_encode</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s2">&quot;bool&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;intersect param&#39;s with_encode </span><span class="si">{}</span><span class="s2"> not supported, should be bool type&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">with_encode</span><span class="p">))</span>

        <span class="k">if</span> <span class="nb">type</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">only_output_key</span><span class="p">)</span><span class="o">.</span><span class="vm">__name__</span> <span class="o">!=</span> <span class="s2">&quot;bool&quot;</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;intersect param&#39;s only_output_key </span><span class="si">{}</span><span class="s2"> not supported, should be bool type&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">is_send_intersect_ids</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">encode_params</span><span class="o">.</span><span class="n">check</span><span class="p">()</span>
        <span class="n">LOGGER</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;Finish intersect parameter check!&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="kc">True</span></div></div>

</pre></div>

           </div>
           
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, FATE_TEAM

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>